package com.sskj.jgxt.impl;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.sskj.core.exception.MException;
import com.sskj.jgxt.RestParamVO;
import com.sskj.jgxt.RestQueryVO;
import com.sskj.jgxt.eng.domain.entity.DingJianDuEng;
import com.sskj.jgxt.jd.vo.JianDuParamVO;
import com.sskj.jgxt.param.EngQueryParam;
import com.sskj.utils.HttpUtils;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import springfox.documentation.annotations.ApiIgnore;

@RestController
@RequestMapping(value = "/wechat/jl", method = { RequestMethod.POST, RequestMethod.GET })
@Api(value = "记录信息", description = "记录信息")
public class WeChartJLServiceImpl {

	protected final Log logger = LogFactory.getLog(WeChartJLServiceImpl.class);

	@Value("${sskj.conf.restUrl}")
	private String restUrl;


	@CrossOrigin(origins = "*", maxAge = 3600)
	@RequestMapping(value = "/jllx", method = { RequestMethod.POST })
	@ApiOperation(value = "通知书查询信息", notes = "通知书查询信息", httpMethod = "POST")
	public JSONObject queryjlbylx(@RequestBody JianDuParamVO o) throws MException {
		JSONObject obj = new JSONObject();

		RestQueryVO data = new RestQueryVO();

		data.setPage(1);
		data.setPageSize(10);
		data.setNameQueryName("wx.jdjlbylx");

		RestParamVO param = new RestParamVO();
		param.setPn("tel");
		if (o.getTel().isEmpty()) {
			param.setValue("88888888888");
		} else {
			param.setValue(o.getTel());
		}
		data.getParams().add(param);

		RestParamVO param2 = new RestParamVO();
		param2.setPn("jllx");

		param2.setValue(o.getJllx());

		data.getParams().add(param2);

		try {

			obj = HttpUtils.httpPostOne(restUrl + "dingtalk/jd/queryjlbylx", data);
			if (obj != null) {
				System.out.println("JSONObject code=" + obj.toJSONString());
			}
		} catch (Exception e) {
			e.printStackTrace();
			throw new MException("request_timeout");
		}

		return obj;
	}
	
	@CrossOrigin(origins = "*", maxAge = 3600)
	@RequestMapping(value = "/jllxca", method = { RequestMethod.POST })
	@ApiOperation(value = "通知书查询信息", notes = "通知书查询信息", httpMethod = "POST")
	public JSONObject queryjlbylxca(@RequestBody JianDuParamVO o) throws MException {
		JSONObject obj = new JSONObject();

		RestQueryVO data = new RestQueryVO();

		data.setPage(1);
		data.setPageSize(10);
		data.setNameQueryName("wx.jdjlbylx");

		RestParamVO param = new RestParamVO();
		param.setPn("tel");
		if (o.getTel().isEmpty()) {
			param.setValue("88888888888");
		} else {
			param.setValue(o.getTel());
		}
		data.getParams().add(param);

		RestParamVO param2 = new RestParamVO();
		param2.setPn("jllx");

		param2.setValue(o.getJllx());

		data.getParams().add(param2);

		try {

			obj = HttpUtils.httpPostOne(restUrl + "dingtalk/jd/queryjlbylxca", data);
			if (obj != null) {
				System.out.println("JSONObject code=" + obj.toJSONString());
			}
		} catch (Exception e) {
			e.printStackTrace();
			throw new MException("request_timeout");
		}

		return obj;
	}	
	
	@CrossOrigin(origins = "*", maxAge = 3600)
	@RequestMapping(value = "/lastmanylx", method = { RequestMethod.POST })
	@ApiOperation(value = "监督信息", notes = "监督信息", httpMethod = "POST")
	public JSONObject lastjlbylx(@RequestBody JianDuParamVO o) throws MException {
		JSONObject obj = new JSONObject();

		RestQueryVO data = new RestQueryVO();

		data.setPage(1);
		data.setPageSize(10);
		data.setNameQueryName("wx.jdjlbylx");
	

		RestParamVO param2 = new RestParamVO();
		param2.setPn("jllx");

		param2.setValue(o.getJllx());

		data.getParams().add(param2);

		try {

			obj = HttpUtils.httpPostOne(restUrl + "dingtalk/jd/lastbylxmany", data);
			if (obj != null) {
				System.out.println("JSONObject code=" + obj.toJSONString());
			}
		} catch (Exception e) {
			e.printStackTrace();
			throw new MException("request_timeout");
		}

		return obj;
	}		
	
	
	@CrossOrigin(origins = "*", maxAge = 3600)
	@RequestMapping(value = "/cajllx", method = { RequestMethod.POST })
	@ApiOperation(value = "ca查询信息", notes = "ca查询信息", httpMethod = "POST")
	public JSONObject querycajlbylxmany(@RequestBody JianDuParamVO o) throws MException {
		JSONObject obj = new JSONObject();

		RestQueryVO data = new RestQueryVO();

		data.setPage(o.getPage());
		data.setPageSize(o.getPageSize());
		data.setNameQueryName("wx.jdjlbylx");


		
		
		RestParamVO param = new RestParamVO();
		param.setPn("tel");
		if (o.getTel().isEmpty()) {
			param.setValue("88888888888");
		} else {
			param.setValue(o.getTel());
		}
		data.getParams().add(param);

		RestParamVO param2 = new RestParamVO();
		param2.setPn("jllx");
		if (o.getJllx().isEmpty()) {
			param2.setValue("否");
		}
		else {
			param2.setValue(o.getJllx());
		}
		

		data.getParams().add(param2);
		
		RestParamVO param5 = new RestParamVO();
		param5.setPn("ishf");

		param5.setValue(o.getJllx());

		data.getParams().add(param5);		
		
		RestParamVO param3 = new RestParamVO();
		param3.setPn("engName");
		if (o.getEngName().isEmpty()) {
			param3.setValue("");
		} else {
			param3.setValue(o.getEngName());
		}
		data.getParams().add(param3);		
		
		RestParamVO param4 = new RestParamVO();
		param4.setPn("jlrqBegin");
		if (null == o.getJlrqBegin() || o.getJlrqBegin().isEmpty()) {
			param4.setValue("");
		} else {
			param4.setValue(o.getJlrqBegin());
		}
		data.getParams().add(param4);				

		try {

			obj = HttpUtils.httpPostOne(restUrl + "dingtalk/jd/queryjlbycamany", data);
			if (obj != null) {
				System.out.println("JSONObject code=" + obj.toJSONString());
			}
		} catch (Exception e) {
			e.printStackTrace();
			throw new MException("request_timeout");
		}

		return obj;
	}		
	
	
	@CrossOrigin(origins = "*", maxAge = 3600)
	@RequestMapping(value = "/fcjllx", method = { RequestMethod.POST })
	@ApiOperation(value = "复查查询信息", notes = "复查查询信息", httpMethod = "POST")
	public JSONObject queryfcjlbylxmany(@RequestBody JianDuParamVO o) throws MException {
		JSONObject obj = new JSONObject();

		RestQueryVO data = new RestQueryVO();

		data.setPage(o.getPage());
		data.setPageSize(o.getPageSize());
		data.setNameQueryName("wx.jdjlbylx");


		
		
		RestParamVO param = new RestParamVO();
		param.setPn("tel");
		if (o.getTel().isEmpty()) {
			param.setValue("88888888888");
		} else {
			param.setValue(o.getTel());
		}
		data.getParams().add(param);

		RestParamVO param2 = new RestParamVO();
		param2.setPn("jllx");

		param2.setValue(o.getJllx());

		data.getParams().add(param2);
		
		RestParamVO param3 = new RestParamVO();
		param3.setPn("engName");
		if (o.getEngName().isEmpty()) {
			param3.setValue("");
		} else {
			param3.setValue(o.getEngName());
		}
		data.getParams().add(param3);		
		
		RestParamVO param4 = new RestParamVO();
		param4.setPn("jlrqBegin");
		if (null == o.getJlrqBegin() || o.getJlrqBegin().isEmpty()) {
			param4.setValue("");
		} else {
			param4.setValue(o.getJlrqBegin());
		}
		data.getParams().add(param4);				

		try {

			obj = HttpUtils.httpPostOne(restUrl + "dingtalk/jd/queryjlbylxmany", data);
			if (obj != null) {
				System.out.println("JSONObject code=" + obj.toJSONString());
			}
		} catch (Exception e) {
			e.printStackTrace();
			throw new MException("request_timeout");
		}

		return obj;
	}	

}
